﻿using AutoMapper;
using B.R.RabbitRoot.Domain.animal_husbandry;
using B.R.RabbitRoot.ErrorCode;
using B.R.RabbitRoot.Infrastructure.Interface;
using B.R.RabbitRoot.Read.API.Applications.Commands.HealthCareInfoCommands;
using B.R.RabbitRoot.Read.API.Dtos;
using MediatR;

namespace B.R.RabbitRoot.Read.API.Applications.CommandHandlers.HealthCareInfoCommandsHandlers
{
    /// <summary>
    /// 保健信息查询命令
    /// </summary>
    public class HealthCareInfoQueryCommandHandler : IRequestHandler<HealthCareInfoQueryCommand, APIResult<List<HealthCareInfoDTO>>>
    {
        private readonly IBaserepository<HealthCareInfo> _HealthCareInfo;
        private readonly IMapper _mapper;

        public HealthCareInfoQueryCommandHandler(IBaserepository<HealthCareInfo> healthCareInfo, IMapper mapper)
        {
            _HealthCareInfo = healthCareInfo;
            _mapper = mapper;
        }
        public async Task<APIResult<List<HealthCareInfoDTO>>> Handle(HealthCareInfoQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<HealthCareInfoDTO>> result = new APIResult<List<HealthCareInfoDTO>>();
            
            var list = _HealthCareInfo.GetAll().Where(m=>m.DeleteIs==false && m.FarmingDetailsId==request.FarmingDetailsId).ToList();
            var entity= _mapper.Map<List<HealthCareInfoDTO>>(list);
            return await Task.FromResult(result.Success(entity));
        }
    }
}
